package com.mdd.front.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.mdd.common.entity.WxCustomer;
import com.mdd.common.entity.user.UserAddress;
import com.mdd.common.mapper.ShopMapper;
import com.mdd.common.mapper.WxCustomerMapper;
import com.mdd.common.util.TimeUtils;
import com.mdd.front.service.IWxCustomerservice;
import com.mdd.front.vo.user.UserAddressVo;
import com.mdd.front.vo.wxcustomer.WxCustomerVo;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

@Service
public class WxCustomerserviceImpl implements IWxCustomerservice {
    @Resource
    WxCustomerMapper wxCustomerMapper;

    @Resource
    ShopMapper  shopMapper;
    /**
     * 根据店铺id获取数据
     * @param shopId
     * @return
     */
    @Override
    public List<WxCustomerVo> getWxCustomerList(Integer shopId) {
        List<WxCustomer> list = wxCustomerMapper.selectList(new QueryWrapper<WxCustomer>()
                .eq("shop_id", shopId));

        List<WxCustomerVo> lists = new ArrayList<>();
        for (WxCustomer wxCustomer : list) {
            WxCustomerVo vo = new WxCustomerVo();
            BeanUtils.copyProperties(wxCustomer, vo);
            vo.setCreateTime(TimeUtils.timestampToDate(wxCustomer.getCreateTime()));
            vo.setUpdateTime(TimeUtils.timestampToDate(wxCustomer.getUpdateTime()));
            vo.setShopName(shopMapper.selectById(wxCustomer.getShopId()).getName());
            lists.add(vo);
        }
        return lists;
    }
}
